﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebeTerm.Web
{
    public abstract class BaseHttpHandler : IHttpHandler
    {
        /// <summary>
        /// Gets a value indicating whether another request can use the <see cref="T:System.Web.IHttpHandler" /> instance.
        /// </summary>
        /// <value><c>true</c> if this instance is reusable; otherwise, <c>false</c>.</value>
        /// <returns>true if the <see cref="T:System.Web.IHttpHandler" /> instance is reusable; otherwise, false.</returns>
        public bool IsReusable
        {
            get { return false; }
        }

        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = ContentType;
            context.Response.Write(ExecuteHandler(context));
        }

        /// <summary>
        /// 执行客户端请求.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>System.String.</returns>
        protected virtual string ExecuteHandler(HttpContext context) {
            return string.Empty;
        }

        /// <summary>
        /// 设置Handler返回数据格式.
        /// </summary>
        /// <value>The type of the content.</value>
        protected virtual string ContentType {
            get {
                return @"text/plain";
            }
        }
    }
}